#include "udpserver.hpp"
#include <memory>

void Usage(string str)
{
    cout<<"/n/r"<<str<<"port"<<endl;
}

string Handle(string& cmd) 
{
    FILE* fp=popen(cmd.c_str(),"r");
    if(fp==nullptr)
    {
        perror("popen error");
        exit(1);
    }

    string ret;
    char str[size];

    while(true)
    {
        char* p=fgets(str,size,fp);//fgets会自己加 '\0'
        if(p==nullptr) break;

        ret+=str;
    }
    pclose(fp);
    return ret; 
}

int main(int argc,char* argv[]) //服务器 要选择自己的端口
{
    
    if(argc!=2)
    {
        Usage(argv[0]);
        exit(0);
    }

    uint16_t port=stoi(argv[1]);
    unique_ptr<Server> svr(new Server(port));

    svr->ServerInit();
    svr->Run(Handle);


    return 0;
}